package com.zhouys.servlet02;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class Servlet02 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf-8");
//        PrintWriter writer = resp.getWriter();
//        writer.println("你好");
//        this.getInitParameter() 初始化参数
//        this.getServletConfig(); servlet配置
//        this.getInitParameter();
//        this.getServletContext(); servlet上下文
        ServletContext servletContext = this.getServletContext();
        String username = "张三";
        servletContext.setAttribute("username",username);//将数据保存在servlet中

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
